package com.leyou.item.api;


import com.leyou.common.pojo.PageResult;
import com.leyou.dto.CartDTO;
import com.leyou.item.pojo.Sku;
import com.leyou.item.pojo.Spu;
import com.leyou.item.pojo.SpuDetail;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: wzh
 * @Date: 2019/3/29 22:29
 * @Description:
 */
public interface GoodsApi {
    /**
     * 分页查询spu
     * @param page 当前页，int
     * @param rows 每页大小，int
     * @param saleable 是否上下架，boolean
     * @param key  搜索关键词，String
     * @return
     */
    @GetMapping("spu/page")
    PageResult<Spu> querySpuByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "5") Integer rows,
            @RequestParam(value = "saleable", required = false) Boolean saleable,
            @RequestParam(value = "key", required = false) String key);



    /**
     * 根据spu的id查询商品详情detail
     * @param spuId
     * @return
     */
    @GetMapping("/spu/detail/{id}")
    SpuDetail querySpuDetailById(@PathVariable("id") Long spuId);

    /**
     * 根据spu的id查询下面的sku的集合
     * @param spuId querySkuBySpuId  spu的id
     * @return sku的集合
     */
    @GetMapping("sku/list")
    List<Sku> querySkuBySpuId(@RequestParam("id") Long spuId);


    /**
     * 根据spu的id查询spu
     * @param id
     * @return
     */
    @GetMapping("spu/{id}")
    Spu querySpuById(@PathVariable("id") Long id);

    /**
     *根据spu的id集合查询所有的sku
     * @param ids
     * @return
     */
    @GetMapping("sku/list/ids")
    List<Sku> querySkuBySpuId(@RequestParam("ids") List<Long> ids);

    /**
     * 减库存
     * @param carts
     * @return
     */
    @PostMapping("stock/decrease")
    Void decreaseStock(@RequestBody List<CartDTO> carts);

}
